package com.example.networkrequestencapsulation;

import android.app.Application;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import androidx.multidex.MultiDex;
import com.example.networkrequestencapsulation.network.ApiConstant;
import com.example.networkrequestencapsulation.network.InitOkGO;
import com.gyf.cactus.Cactus;

/**
 * 作者 : chenyixi
 * 日期 : 2019/11/19 18:34
 * 文件包名 : com.example.networkrequestencapsulation
 * 描述 :
 */
public class CustomApplication extends Application {

    private static Context context;//全局Context

    public static Context getInstance() {
        return context;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();

        //初始化网络请求框架okgo
        InitOkGO.initOkGO(this);

        //初始化进程保活
        initCactus();

        //初始化分包框架
        MultiDex.install(this);

    }

    private void initCactus() {

        Intent intent = new Intent();
        intent.setClass(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        Cactus.getInstance()
                .isDebug(ApiConstant.isDebug)
                .setPendingIntent(pendingIntent)
                .register(this);
    }
}
